<template>
  <!-- @command 点击了下拉菜单 的选项后触发 , 实参值为 el-dropdown-item 身上的command属性 -->
  <el-dropdown trigger="click" @command="changeLanguage">
    <div>
      <svg-icon class="langIcon" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh" :disabled="'zh'=== $i18n.locale ">中文</el-dropdown-item>
      <el-dropdown-item command="en" :disabled="'en'=== $i18n.locale ">English</el-dropdown-item>
      <el-dropdown-item command="ja" :disabled="'ja'=== $i18n.locale ">日本語</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  name: 'Lang',
  methods: {
    changeLanguage(lang) { // lang就是 command="值"
      this.$i18n.locale = lang // 设置给本地的i18n插件
      this.$message.success('切换多语言成功')
    }
  }
}
</script>

<style lang="scss" scoped>
.langIcon{
    color:#fff;
    font-size:21px;
    transform: translateY(4px);
    margin-right:10px
}
</style>
